package cn.calm.study.hibernate.many2one.dao.impl;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import cn.calm.study.hibernate.many2one.Dialog;
import cn.calm.study.hibernate.many2one.dao.IMany2OneDao;

public class Many2OneDaoImpl extends HibernateDaoSupport implements
		IMany2OneDao {

	@Override
	public Dialog loadById(String id) {
		return getHibernateTemplate().get(Dialog.class, id);
	}

	@Override
	public void save(Dialog dialog) {
		getHibernateTemplate().save(dialog);
	}

	@Override
	public void update(Dialog dialog) {
		Session session=getHibernateTemplate().getSessionFactory().openSession();
		Query q=session.createQuery("delete from cn.calm.study.hibernate.many2one.Button where dialog = :dialog");
		q.setEntity("dialog", dialog);
		q.executeUpdate();
		getHibernateTemplate().update(dialog);
	}

	@Override
	public void delete(Dialog dialog) {
		getHibernateTemplate().delete(dialog);
	}

	@Override
	public void deleteByDialog(Dialog dialog) {
		
	}
}
